﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Plexi
{
	internal static class MathTools
	{
		/// <summary>
		/// Normalizes angle between -180 and 180.
		/// http://stackoverflow.com/a/2323034
		/// </summary>
		internal static double NormalizeLongitude(double d)
		{
			d = ((d % 360) + 360) % 360;
			return d > 180 ? d - 360 : d;
		}

		/// <summary>
		/// Produces a unique integer from two non-negative integers.
		/// http://stackoverflow.com/a/919661
		/// http://en.wikipedia.org/wiki/Pairing_function#Cantor_pairing_function
		/// <para>
		/// This could create very large numbers, but we're only using it with ints up to 720, where the result won't be higher than 1038240.
		/// </para>
		/// </summary>
		internal static int CantorPairing(int k1, int k2)
		{
			return ((k1 + k2) / 2) * (k1 + k2 + 1) + k2;
		}
	}
}
